<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library"
  xmlns:BlogLibrary="urn:BlogLibrary"
  xmlns:Blog="urn:Blog"
  exclude-result-prefixes="msxml umbraco.library BlogLibrary Blog">

  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>
  <xsl:variable name="currentBlog" select="Blog:XmlCurrent(number($currentPage/@id))" />

  <xsl:template match="/">

    <xsl:if test="count($currentPage/Comments/Comment) &gt; 0">
      <section>
        <header>
          <h3>
            <xsl:value-of select="count($currentPage//Comment)"/> comment<xsl:if test="count($currentPage//Comment) &gt; 1">s</xsl:if>  for  &#8220;<xsl:value-of select="$currentPage/@nodeName"/>&#8221;
          </h3>

        </header>

        <xsl:apply-templates select="$currentPage/Comments/Comment">
          <xsl:sort select="@createDate" order="descending"/>
        </xsl:apply-templates>
      </section>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Comment">
    <article>
      <xsl:attribute name="class">
        comment<xsl:if test="position() mod 2 = 1"> alt</xsl:if>
      </xsl:attribute>
      <xsl:attribute name="id">
        comment-<xsl:value-of select="@id" />
      </xsl:attribute>
      <header>
        <h4>
          <xsl:value-of select="@nodeName"/>
        </h4>
        <div class="comment-author vcard">
          <img class="photo avatar avatar-32 photo" width="32" height="32" src="{BlogLibrary:GetGravatar(./email, 40, '')}" alt="Gravatar of {./name}"/>
          <span class="fn n">
            <xsl:choose>
              <xsl:when test="string-length(./website) = 0">
                <xsl:value-of select="./name"/>
              </xsl:when>
              <xsl:otherwise>
                <a class="url" rel="external nofollow" href="{./website}" _target="blank">
                  <xsl:value-of select="./name"/>
                </a>
              </xsl:otherwise>
            </xsl:choose>
          </span>
        </div>
        <div class="comment-meta">
          Posted <time class="published" datetime="{./@createDate}">
            <xsl:value-of select="umbraco.library:LongDate(./@createDate, 1, ' at ' )"/>
          </time>
        </div>
        <xsl:choose>
          <xsl:when test="string($currentPage/closeComments) = '1' or string($currentBlog/disableComments) = '1'"></xsl:when>
          <xsl:otherwise>
            <a class="comment-reply" href="#respond">Reply to this comment...</a>
          </xsl:otherwise>
        </xsl:choose>
      </header>
      <section>
        <xsl:value-of select="./bodyText" disable-output-escaping="yes"/>
      </section>
      <section class="child-comments">
        <xsl:if test="count(./Comment) &gt; 0">
          <xsl:apply-templates select="./Comment">
            <xsl:sort select="createDate"/>
          </xsl:apply-templates>
        </xsl:if>
      </section>
    </article>

  </xsl:template>
</xsl:stylesheet>